/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DaneUser.java
 *
 * Created on 2013-02-13, 16:48:01
 */

package wkfquestions;

/**
 *
 * @author Przemo
 */
public class DaneUser extends javax.swing.JFrame {
    WindowTestTrueFalse ExamTF = new WindowTestTrueFalse();
    WindowTestABCD ExamABCD = new WindowTestABCD();

    boolean przycisk_egzamin;
    int a; //zmienna pomocnicza

    boolean czyTF; //true jestli pytania prawda fałsz, false jeśli pytania ABCD

    /** Creates new form DaneUser */
    public DaneUser() {
        initComponents();
        initMyComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        textField1 = new java.awt.TextField();
        textField2 = new java.awt.TextField();
        button1 = new java.awt.Button();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        textField3 = new java.awt.TextField();
        label4 = new java.awt.Label();
        label5 = new java.awt.Label();
        label6 = new java.awt.Label();
        bWstecz = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        textField1.setText("textField1");
        textField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textField1ActionPerformed(evt);
            }
        });

        textField2.setText("textField2");

        button1.setLabel("Rozpocznij Egzamin");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        label1.setText("Imię:");

        label2.setText("Nazwisko:");

        label3.setText("Liczba pytań:");

        textField3.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        textField3.setText("textField3");

        label4.setText("label4");

        label5.setText("label5");

        label6.setAlignment(java.awt.Label.CENTER);
        label6.setText("label6");

        bWstecz.setLabel("Wstecz");
        bWstecz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bWsteczActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label6, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(textField1, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(textField2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(textField3, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(92, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(159, 159, 159))))
            .addGroup(layout.createSequentialGroup()
                .addGap(138, 138, 138)
                .addComponent(bWstecz, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(185, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(bWstecz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
        
        if(czy_blad()){//jeśli jest błąd wpisania liczby pytań
            label4.setText("Ustaw prawidlowa liczbe");
            System.out.println(a);
        }
        
        else{ //jeśli nie ma błędu
            if(czyTF){
               if(przycisk_egzamin){//egzamin z pytań
                    UstawWindowTestTF(true);
                }
                else{//przegląd pytań po kolei
                    UstawWindowTestTF(false);
                }
            }

            else{
               if(przycisk_egzamin){//egzamin z pytań
                    UstawWindowTestABCD(true);
                }
                else{//przegląd pytań po kolei
                    UstawWindowTestABCD(false);
                }
            }
        }
    }//GEN-LAST:event_button1ActionPerformed

    private void textField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textField1ActionPerformed

    private void bWsteczActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bWsteczActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();

        KumiteTrueFalse kumiteTF = new KumiteTrueFalse();
        kumiteTF.setVisible(true);
    }//GEN-LAST:event_bWsteczActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DaneUser().setVisible(true);
            }
        });
    }

    void ZerujTextFields(){
        textField1.setText("");
        textField2.setText("");
        textField3.setText("");
        label4.setText("");
        label6.setText("");
    }

    void UstawLabel6(String tekst){
        label6.setText(tekst);
    }

    void UstawLabel3(String tekst){
        label3.setText(tekst);
    }

    void UstawButton1(String tekst){
        button1.setLabel(tekst);
    }

    void UkryjLabel12TextField12(){
        label1.setVisible(false);
        label2.setVisible(false);
        textField1.setVisible(false);
        textField2.setVisible(false);
    }

    boolean czy_blad(){
        
        boolean blad = false;
        try{
            a = Integer.parseInt(textField3.getText()); //przypisanie do zmiennej wpisanej wartości
        }
        catch(RuntimeException e){//sprawdzenie czy wpisana poprawna liczba
         //   blad = true;
            this.setVisible(true);
            return true;
        }

        //jeśli liczba wpisana ze złego zakresu
        int pomoc;
        if(czyTF){
            pomoc = ExamTF.pytaniaTF.liczba_pytan;
        }
        else{
            pomoc = ExamABCD.pytaniaABCD.liczba_pytan;
        }
        if(!blad && (a > pomoc || a <=0)){
            this.setVisible(true);
            //blad = true;
            return true;
        }
        return false;
    }

    void PrzyciskEgzaminTrue(){
        przycisk_egzamin = true;
    }

    void UstawWindowTestTF(boolean egzamin){
        if(egzamin){//okno dla egzaminu
                ExamTF.UstawLiczbePytan(a);
                ExamTF.UstawLabelPytanie("Wciśnij start, by rozpocząć egzamin");
                ExamTF.UstawLabelDobrzeZle("");
                ExamTF.UstawLabelKomentarz("");
                ExamTF.UstawImieNazwisko(textField1.getText(), textField2.getText());
                ExamTF.ToEgzamin();
                ExamTF.UkryjPrzyciskiTrueFalseNext();

                ExamTF.setVisible(true);
        }

        else{ //okno dla pytań po kolei
                ExamTF.TF_po_kolei = true;
                ExamTF.UstawPoczatkowePytanie(a);
                ExamTF.UstawLabelPytanie("Wciśnij Start, by rozpocząć wyświetlanie pytań");
                ExamTF.UstawLabelDobrzeZle("");
                ExamTF.UstawLabelKomentarz("");
                ExamTF.UkryjPrzyciskiTrueFalseNext();

                ExamTF.setVisible(true);
        }
    }

    void UstawWindowTestABCD(boolean egzamin){
        if(egzamin){//okno dla egzaminu
                ExamABCD.UstawLiczbePytan(a);
                ExamABCD.UstawLabelPytanie("Wciśnij start, by rozpocząć egzamin ABCD");
                ExamABCD.UstawLabelDobrzeZle("");
                ExamABCD.UstawLabelKomentarz("");
                ExamABCD.UstawImieNazwisko(textField1.getText(), textField2.getText());
                ExamABCD.ToEgzamin();
                ExamABCD.UkryjPrzyciskiTrueFalseNext();

                ExamABCD.setVisible(true);
        }

        else{ //okno dla pytań po kolei
                ExamABCD.TF_po_kolei = true;
                ExamABCD.UstawPoczatkowePytanie(a);
                ExamABCD.UstawLabelPytanie("Wciśnij Start, by rozpocząć wyświetlanie pytań ABCD");
                ExamABCD.UstawLabelDobrzeZle("");
                ExamABCD.UstawLabelKomentarz("");
                ExamABCD.UkryjPrzyciskiTrueFalseNext();

                ExamABCD.setVisible(true);
        }
    }

    void UstawCzyTF(boolean a){
        czyTF = a;
    }

    void initMyComponents(){ //zmienne, które sam inicjuję
        a = 0;
        przycisk_egzamin = false;
        this.setTitle("Wstęp do egzaminu");
        if(czyTF){
            label5.setText("maksymalnie " + Integer.toString(ExamTF.pytaniaTF.liczba_pytan));
        }
        else{
            label5.setText("maksymalnie " + Integer.toString(ExamABCD.pytaniaABCD.liczba_pytan));
        }
        
       // czyTF = true; //domyslnie pytania prawda falsz
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button bWstecz;
    private java.awt.Button button1;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label label4;
    private java.awt.Label label5;
    private java.awt.Label label6;
    private java.awt.TextField textField1;
    private java.awt.TextField textField2;
    private java.awt.TextField textField3;
    // End of variables declaration//GEN-END:variables

}
